package _07_串;

public class _58_最后一个单词的长度 {

    public static void main(String[] args) {
        String str = "luffy is still joyboy";
        System.out.println(lengthOfLastWord(str));
    }

    public static int lengthOfLastWord(String s) {
        char[] chars = s.toCharArray();
        int count = 0;
        for (int i = chars.length - 1; i >= 0; i--) {
            if (chars[i] == ' ' && count == 0) continue;
            else if (chars[i] == ' ') break;
            count++;
        }
        return count;
    }
}
